home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Resources / General / ProNET / src / drivers / serial.s < prev   
Text File  |  1996-11-30  |  6KB  |  310 lines

  1. *
  2. * serial (ProNET driver)
  3. *
  4.  
  5. ** This driver does not work correctly with 8n1.device 37.13
  6.  
  7. ; Format of one packet
  8. ; 2bytes    "R!" for packet recognization
  9. ; 2bytes    Length in Bytes of pure data without next two words
  10. ; 2bytes    Destination Port
  11. ; 2bytes    source Port
  12. ; xbytes    Data
  13.  
  14.         include    "A:OSmacros.i"
  15.         include    "exec/exec.i"
  16.         include    "devices/serial.i"
  17.         include    "P:include/devices/pronet.i"
  18.         include    "exec_lib.i"
  19.  
  20. Init
  21.         movem.l    d2-d7/a2-a6,-(sp)
  22.         move.l    a0,a4
  23.         move.l    a1,a5
  24.         cmp.l    #"RST!",d0        ;compare ID
  25.         bne    .ende
  26.         cmp.l    #2,d1            ;0 was the error condition
  27.         bne.s    .ende            ;in ProNET V2/V3
  28.  
  29.         bsr    StartDevice
  30.         tst.w    d0
  31.         beq.s    .ende
  32.  
  33.         move.l    serialio(pc),a0
  34.         move.l    MN_REPLYPORT(a0),a0
  35.         move.b    MP_SIGBIT(a0),pndd_ReadSignalBit(a4)
  36.         move.l    #ReadQuery,pndd_ReadQuery(a4)
  37.         move.l    #ReadFlush,pndd_ReadFlush(a4)
  38.         move.l    #Read,pndd_Read(a4)
  39.         move.l    #Write,pndd_Write(a4)
  40.         move.l    #Exit,pndd_Exit(a4)
  41.  
  42.         clr.l    RC
  43.  
  44. .ende        movem.l    (sp)+,d2-d7/a2-a6
  45.         move.l    RC(pc),d0
  46.         rts
  47.  
  48. RC        dc.l    0
  49.  
  50.         dc.b    "$VER: serial 37.0 (30.11.96)",13,10,0
  51.         even
  52.  
  53. Exit        movem.l    d2-d7/a2-a6,-(sp)
  54.         bsr    StopDevice
  55.         movem.l    (sp)+,d2-d7/a2-a6
  56.         rts
  57.  
  58. ; -- Start the right `serial.device'
  59. StartDevice    move.l    4.w,a6
  60.  
  61.         move.l    #PNDRVERR_NO_MEMORY,RC
  62.         moveq    #IOEXTSER_SIZE,d0
  63.         bsr    GetIORequest
  64.         move.l    d0,serialio
  65.         beq    noiorequest
  66.  
  67.         moveq    #IOEXTSER_SIZE,d0
  68.         bsr    GetIORequest
  69.         move.l    d0,serialiow
  70.         beq    noiorequest2
  71.  
  72.         move.l    serialio(pc),a2
  73.         move.b    #SERF_7WIRE,IO_SERFLAGS(a2)
  74.         move.l    a5,a0            ;device name
  75. .0        move.b    (a0)+,d0
  76.         cmp.b    #" ",d0
  77.         bhi.s    .0
  78.         clr.b    -1(a0)
  79.  
  80.         bsr    dec2long
  81.         move.l    d1,d5            ;unit
  82.         bsr    dec2long
  83.         move.l    d1,d6            ;baudrate
  84.  
  85.         move.b    #SERF_XDISABLED^SERF_RAD_BOOGIE^SERF_7WIRE,d7
  86.         lea    threeweestring(pc),a1
  87.         tst.b    -1(a0)
  88.         beq.s    .7wire            ;3 or 7 wire??
  89.         moveq    #4,d0
  90. .test3wire    move.b    (a0)+,d1
  91.         cmp.b    #"A",d1
  92.         bcs.s    .nochar
  93.         bclr    #5,d1
  94. .nochar        cmp.b    (a1)+,d1
  95.         dbne    d0,.test3wire
  96.         bne.s    .7wire
  97.         bclr    #SERB_7WIRE,d7
  98.         bclr    #SERB_7WIRE,IO_SERFLAGS(a2)
  99. .7wire
  100.         move.l    a5,a0
  101.         move.l    d5,d0
  102.         move.l    a2,a1
  103.         moveq    #0,d1
  104.         LIBCALL    OpenDevice
  105.         move.l    #err1,RC
  106.         tst.b    d0
  107.         bne    nodevice
  108.  
  109.         move.l    a2,a0
  110.         move.l    serialiow(pc),a1
  111.         move.l    a1,a2
  112.         move.l    MN_REPLYPORT(a2),d2
  113.         moveq    #IOEXTSER_SIZE,d0
  114.         LIBCALL    CopyMem
  115.         move.l    d2,MN_REPLYPORT(a2)
  116.         move.w    #CMD_WRITE,IO_COMMAND(a2)
  117.  
  118.         move.l    serialio(pc),a1
  119.         move.w    #SDCMD_SETPARAMS,IO_COMMAND(a1)
  120.         move.b    d7,IO_SERFLAGS(a1)
  121.         move.l    d6,IO_BAUD(a1)
  122.         move.l    #16384,IO_RBUFLEN(a1)
  123.         clr.l    IO_EXTFLAGS(a1)
  124.         move.b    #8,IO_READLEN(a1)
  125.         move.b    #8,IO_WRITELEN(a1)
  126.         move.b    #1,IO_STOPBITS(a1)
  127.         clr.b    IO_FLAGS(a1)
  128.         LIBCALL    DoIO
  129.         move.l    #err2,RC
  130.         tst.b    d0
  131.         bne.s    noparams
  132.  
  133.         bsr.s    IssueReadCMD
  134.         moveq    #-1,d0
  135.         rts
  136.  
  137. err1        dc.b    "Can't open specified serial.device.",0
  138. err2        dc.b    "Couldn't set serial parameters.",0
  139.         even
  140.  
  141. StopDevice    move.l    4.w,a6
  142.         move.l    serialio(pc),a1
  143.         LIBCALL    AbortIO
  144.         move.l    serialio(pc),a1
  145.         LIBCALL    WaitIO
  146. noparams    move.l    serialio(pc),a1
  147.         LIBCALL    CloseDevice
  148. nodevice    move.l    serialiow(pc),a0
  149.         bsr    FreeIORequest
  150. noiorequest2    move.l    serialio(pc),a0
  151.         bsr    FreeIORequest
  152. noiorequest    moveq    #0,d0
  153.         rts
  154.  
  155. threeweestring    dc.b    "3WIRE"
  156.         even
  157.  
  158. ; -- Put Out An 8 Bytes Read Command
  159. IssueReadCMD    move.l    serialio(pc),a0
  160.         move.l    MN_REPLYPORT(a0),a0
  161.         move.b    MP_SIGBIT(a0),d2
  162.         moveq    #0,d0
  163.         moveq    #0,d1
  164.         bset    d2,d1
  165.         LIBCALL    SetSignal
  166.         move.l    serialio(pc),a1
  167.         move.w    #CMD_READ,IO_COMMAND(a1)
  168.         clr.b    IO_FLAGS(a1)
  169.         move.l    #buffer,IO_DATA(a1)
  170.         move.l    #8,IO_LENGTH(a1)
  171.         move.l    4.w,a6
  172.         LIBJMP    SendIO
  173.  
  174. ReadQuery
  175.         movem.l    d3-d7/a2-a6,-(sp)
  176.         move.l    serialio(pc),a0
  177.         move.l    MN_REPLYPORT(a0),a0
  178.         move.l    4.w,a6
  179.         LIBCALL    GetMsg
  180.         tst.l    d0
  181.         beq.s    .nope
  182.         move.w    buffer(pc),d0
  183.         cmp.w    #"R!",d0
  184.         beq.s    .ok0
  185.  
  186.         bsr    ReadEmpty
  187.         bsr    IssueReadCMD
  188. .nope        moveq    #0,d0
  189.         bra.s    .ende
  190.  
  191. .ok0        movem.w    buffer+2(pc),d0-d2
  192. .ende        movem.l    (sp)+,d3-d7/a2-a6
  193.         rts
  194.  
  195. ReadFlush
  196.         movem.l    d2-d7/a2-a6,-(sp)
  197.         move.l    4.w,a6
  198.         moveq    #0,d2
  199.         move.w    buffer+2(pc),d2
  200. .1        move.l    d2,d0
  201.         cmp.l    #64,d0
  202.         bls.s    .0
  203.         moveq    #64,d0
  204. .0        sub.l    d0,d2
  205.         move.l    serialio(pc),a1
  206.         move.l    #clrbuffer,IO_DATA(a1)
  207.         move.l    d0,IO_LENGTH(a1)
  208.         move.w    #CMD_READ,IO_COMMAND(a2)
  209.         clr.b    IO_FLAGS(a1)
  210.         LIBCALL    DoIO
  211.         tst.l    d2
  212.         bne.s    .1
  213.         bra.s    read_entry
  214.  
  215. Read
  216.         movem.l    d2-d7/a2-a6,-(sp)
  217.         move.l    4.w,a6
  218.         move.l    serialio(pc),a1
  219.         move.l    a0,IO_DATA(a1)
  220.         moveq    #0,d0
  221.         move.w    buffer+2(pc),d0
  222.         move.l    d0,IO_LENGTH(a1)
  223.         move.w    #CMD_READ,IO_COMMAND(a1)
  224.         clr.b    IO_FLAGS(a1)
  225.         LIBCALL    DoIO
  226. read_entry    bsr    IssueReadCMD
  227.         movem.l    (sp)+,d2-d7/a2-a6
  228.         rts
  229.  
  230. Write
  231.         movem.l    d2-d7/a2-a6,-(sp)
  232.         move.l    serialiow(pc),a2
  233.         move.l    4.w,a6
  234.  
  235.         move.l    a0,a3
  236.         move.l    d0,d3
  237.  
  238.         lea    sendbuffer(pc),a5
  239.         move.w    d0,2(a5)
  240.         move.w    d1,4(a5)
  241.         move.w    d2,6(a5)
  242.         move.l    a5,IO_DATA(a2)
  243.         move.l    #8,IO_LENGTH(a2)
  244.         clr.b    IO_FLAGS(a2)
  245.         move.l    a2,a1
  246.         LIBCALL    DoIO
  247.  
  248.         move.l    a3,IO_DATA(a2)
  249.         move.l    d3,IO_LENGTH(a2)
  250.         clr.b    IO_FLAGS(a2)
  251.         move.l    a2,a1
  252.         LIBCALL    DoIO
  253.  
  254.         moveq    #0,d0
  255.         movem.l    (sp)+,d2-d7/a2-a6
  256.         rts
  257.  
  258. buffer        ds.b    8
  259.  
  260. sendbuffer    dc.b    "R!"
  261.         dc.w    0,0,0
  262.  
  263. ; -- A received message did not contain the "R!" string (probably
  264. ; -- the BaudBandit.device startup message), so clear it!
  265. ReadEmpty    move.l    serialio(pc),a2            * CMD_CLEAR
  266.         move.l    4.w,a6                * does not help!
  267. .loop        move.w    #SDCMD_QUERY,IO_COMMAND(a2)    * so we have to read
  268.         move.l    a2,a1                * it out!
  269.         clr.b    IO_FLAGS(a1)
  270.         LIBCALL    DoIO
  271.         move.l    IO_ACTUAL(a2),d0
  272.         beq.s    .ende
  273.         cmp.l    #64,d0
  274.         bcs.s    .ok0
  275.         moveq    #64,d0
  276. .ok0        move.l    d0,IO_LENGTH(a2)
  277.         move.l    #clrbuffer,IO_DATA(a2)
  278.         move.w    #CMD_READ,IO_COMMAND(a2)
  279.         move.l    a2,a1
  280.         clr.b    IO_FLAGS(a1)
  281.         LIBCALL    DoIO
  282.         bra.s    .loop
  283. .ende        rts
  284.  
  285.  
  286. dec2long    ; konvertiert Dezimalstring ab (a0) zu Longword in D1 !!
  287.         moveq    #0,d1
  288. .loop        moveq    #0,d0
  289.         move.b    (a0)+,d0
  290.         sub.b    #"0",d0
  291.         cmp.b    #9,d0
  292.         bhi.s    .oki
  293.         move.l    d1,d2
  294.         lsl.l    #3,d1
  295.         add.l    d2,d1
  296.         add.l    d2,d1
  297.         add.l    d0,d1
  298.         bra.s    .loop
  299. .oki        rts
  300.  
  301. serialio    dc.l    0
  302. serialiow    dc.l    0
  303.  
  304.  
  305.         include    "P:include/devio.s"
  306.  
  307.         section    b,bss
  308.  
  309. clrbuffer    ds.b    64
  310.